package com.xindacloud.sms.portal.controller;

import com.xindacloud.sms.portal.entity.SmsAgent;
import com.xindacloud.sms.portal.service.ISmsAgentService;
import com.xindacloud.sms.portal.vo.SmsAgentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = {"短信通道接口"})
@RestController
@RequestMapping(value = "/api/v1/portal/agent")
@Slf4j
public class AgentController {


    final ISmsAgentService agentService;

    @Autowired
    public AgentController(ISmsAgentService agentService) {
        this.agentService = agentService;
    }

    @ApiOperation(value = "查询所有通道组", response = SmsAgentVO.class)
    @GetMapping(value = "/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object getAllAgentList() {

        final List<SmsAgent> smsAgents = agentService.queryAllAgent();
        return smsAgents.stream()
                .map(rs -> SmsAgentVO.builder()
                        .agentId(rs.getAgentId())
                        .agentName(rs.getAgentName())
                        .build())
                .collect(Collectors.toList());
    }

}
